package com.xuantu.learn.core.thread;

import java.time.LocalTime;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 要求：使用定时器,间隔 4 秒执行一次，再间隔 2 秒执行一次，以此类推执行。
 * @author fengzp
 *
 */
public class TimerTast {

	private static volatile int count = 0;

	class TimerTastCus extends TimerTask {

		@Override
		public void run() {
			count = (count + 1) % 2;
			System.err.println("Boob boom ");
			new Timer().schedule(new TimerTastCus(), 2000 + 2000 * count);
		}

	}

	public static void main(String[] args) {
		Timer timer = new Timer();
		timer.schedule(new TimerTast().new TimerTastCus(), 2000 + 2000 * count);
		while (true) {
			System.out.println(LocalTime.now().getSecond());
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}
